"""
后台首页方法
"""
from selenium import webdriver
from common.base import Base
from selenium.webdriver.common.by import By


class BackstageHome(Base):
    # 点击订单管理
    def click_order_management(self):
        self.driver.switch_to.frame("menu-frame")
        self.click((By.XPATH, "/html/body/div/div[3]/div[1]/ul/li[4]"))

    # 点击订单列表
    def click_order_list(self):
        self.click((By.LINK_TEXT, "订单列表"))

    # 返回第一个订单的订单号
    def order_num(self):
        self.driver.switch_to.default_content()
        self.driver.switch_to.frame("main-frame")
        return self.get_element_text((By.ID, "order_0"))


if __name__ == '__main__':
    # 创建浏览器驱动对象
    options = webdriver.ChromeOptions()
    options.add_argument(r'--user-data-dir=C:\Users\赵霜蜻\AppData\Local\Google\Chrome\User Data')
    driver = webdriver.Chrome(options=options)
    backstage_home = BackstageHome(driver)
    # 访问目标网址
    backstage_home.get("http://localhost:8080/ecshop/admin/index.php")
    backstage_home.click_order_management()
    backstage_home.click_order_list()
    backstage_home.order_num()
    backstage_home.quit(2)
